package Thread;
//中断线程(让对应的线程入口函数执行完毕)
//使用一个boolean变量来作为循环的结束
public class ThreadDemo5 {
    private static boolean flag=true;

    public static  void main(String[] args) throws InterruptedException {
        Thread t=new Thread(){
            @Override
            public void run() {
                while (flag){
                    System.out.println("线程正在运行");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        };
        t.start();
        Thread.sleep(3000);
        flag=false;
    }

}
